using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

using Tino.Core.Data;
using Tino.Core.DBUpdates;

namespace Tino.Core
{
    public class MetaInfo : ISqliteTable
    {
        public MetaInfo() { }

        public int GetDBVersion()
        {
            string SQL = "SELECT Value FROM MetaInfo WHERE Key = 'DBVERSION';";
            return Convert.ToInt32(SqliteAdapter.Get().ExecuteScalar(SQL));
        }

        #region ISqliteTable Members

        public void CreateTable()
        {
            StringBuilder sb = new StringBuilder("CREATE TABLE [MetaInfo] ( ");
            sb.Append("Key VARCHAR NOT NULL, ");
            sb.Append("Value VARCHAR NOT NULL ) ");

            SqliteAdapter.Get().ExecuteNonQuery(sb.ToString());

            string SQL = "INSERT INTO MetaInfo(Key, Value) Values(@Key, @Value);";
            SqliteAdapter.Get().ExecuteNonQuery(SQL, "@Key", "DBVERSION", "@Value", DBUpdater.DB_VERSION_EXPECTED);
        }

        #endregion
    }
}
